﻿@using ExpressManagement.Areas.BackSys.ServiceTools;
@using DAL;
@using Microsoft.AspNetCore.Http;
@if (IsSectionDefined("CssLink"))
{
    @RenderSection("CssLink");
}
@if (IsSectionDefined("Style"))
{
    @RenderSection("Style");
}


@RenderBody()

    <link href="~/Content/backSys/js/advanced-datatable/css/demo_page.css" rel="stylesheet" />
    <link href="~/Content/backSys/js/advanced-datatable/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/backSys/js/data-tables/DT_bootstrap.css" />
    <script type="text/javascript" language="javascript" src="~/Content/BackSys/js/advanced-datatable/js/jquery.dataTables.js"></script>
    <script src="~/Content/BackSys/js/dynamic_table_init.js"></script>
    <script type="text/javascript" src="~/Content/BackSys/js/data-tables/DT_bootstrap.js"></script>
<script>

        $("li a").mouseover(function () {
            $(this).css('cursor', 'pointer');
        })
        function trigger_stay(params) {
            $('#act').val('keep');
        }
        function trigger_update(params) {
            $('#act').val('update');
        }
        function trigger_delete(params) {
            $('#act').val('delete');
        }
        function trigger_add(params) {
            $('#act').val('add');
        }


        function removeNullOrUndefined(obj) {
            //typeof 返回的是字符串，有六种可能："number"、"string"、"boolean"、"object"、"function"、"undefined"
            if (typeof (obj) == "undefined" || obj == "" || obj == null || obj == "null" || obj.length == 0) {
                return "";
            } else {
                //删除全是空格的情况
                var regu = "^[ ]+$";
                var re = new RegExp(regu);
                if (re.test(obj)) {
                    return "";
                } else {
                    return obj;
                }

            }
        }
            function FillTable(datas, target_table = 'table_body', mode = '用户') {
                var html = [];
                //html.push(' <table class="table table-striped table-bordered templatemo-user-table" style="margin-left: 0;">');
                //html.push(' <thead><tr><th>序号</th><th>项目名称</th><th>类别</th><th>发起人</th><th>单位</th><th>详情</th><th>操作</th></tr></thead><tbody>');
                datas.forEach(function (item, index, self) {
                    ID = removeNullOrUndefined(datas[index].ID);
                    html.push('<tr class="gradeA">');
                    html.push('<td class="center hidden-phone">' + ID + '</td>');
                    html.push('<td class="center hidden-phone">' + formatDateTime2(removeNullOrUndefined(datas[index].AddTime)) + '</td>');
                    html.push('<td class="center hidden-phone">' + formatDateTime2(removeNullOrUndefined(datas[index].UpdateTime)) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].UserName) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].UserPass) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].TrueName) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].Phone) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].Email) + '</td>');
                    html.push('<td class="center hidden-phone">' + removeNullOrUndefined(datas[index].ContactAddress) + '</td>');
                    html.push('<td class="center hidden-phone">');
                    html.push('<button class="btn btn-default" type="button" data-toggle="modal" data-target="#dispModal" onclick="get_info(\'' + ID + '\',' + '\'r\'' + ')">查看</button>');

                    html.push('<button class="btn btn-info" type="button" data-toggle="modal" data-target="#updateModal" onclick="get_info(\'' + ID + '\',' + '\'w\'' + ')"> 修改</button >');

                    html.push('<button class="btn btn-danger" type="button" data-toggle="modal" data-target="#delModal" onclick="delete_info(\'' + ID + '\')"> 删除</button >');
                    html.push('</td>');
                    html.push('</tr>');
                })
                var mainObj = $('#' + target_table);
                mainObj.empty();
                mainObj.html(html.join(''));
            }


            //向页面添加消息
            function ShowMessage(message) {
                /*$('#list').append('<li>' + message + '</li>');*/
                $('#messageCenter').prepend('<li class="new" id=\''+12+ '\'> <a href = "" ><span class="label label-danger"><i class="fa fa-bolt"></i></span> <span class="name">' + message + '.  </span><em class="small">' + Date.now() + '</em></a ></li > ');
                //var html = [];
                //html.push('<li class="new">');
                //html.push('<a><span class="label label-danger">')
                //html.push('<i class="fa fa-bolt"></i>');
                //html.push('</span>')
                //html.push(' <span class="name">' + message + '.  </span>');
                //html.push('<em class="small">' + Date.now() + '</em>');
                //html.push('</a>');
                //html.push('</li>');

                //alert(message)
                var messageNum = 0;
                if (sessionStorage.getItem("messageNum") != "")
                    messageNum = parseInt(sessionStorage.getItem("messageNum"));
                sessionStorage.setItem("messageNum", messageNum + 1);
                $('messageNum').css("style", "visibility:visible");
                //$('#messageMenu').click();
            }

            function hasRead(id) {
                messageNum = parseInt(sessionStorage.getItem("messageNum"));
                messageNum -= 1;
                if (messageNum == 0) {
                    $('messageNum').css("style", "visibility:hidden");
                }
                $(id).remove();
            }
            function hasReadAll() {
                lastIndex = $('#messageCenter li').length-1;

                //$('#messageCenter').append('<li class="new"><a >所有通知设置为已读</a></li>');
                //$('#messageCenter').append('<li class="new"><a >所有通知设置为已读</a></li>');
                //$('#messageCenter').append('<li class="new"><a >所有通知设置为已读</a></li>');

                $('#messageCenter li').each(function (index, domele) {
                    console.log(index);
                    if (index != lastIndex) {
                        domele.remove();
                    }


                })

            }

            function callReady() {
                $.ajax({
                            url: "@Url.Action("Ready","Welcome")",
                            type: 'post',
                            data: {},
                            dataType: 'JSON',
                            cache: false,
                            processData: false,
                             contentType: false,
                            error: function () {
                                console.log("22222");
                            },
                            success: function (data) {
                                //data = JSON.stringify(data);
                                console.log(data);

                              }

                          });
                  }

            //设置cookie
        function setCookie(name, value) {
            console.log('setcookie' + '  ' + value);
                delCookie(name);
                document.cookie = name + "=" + escape(value);
                //document.cookie = name + "=" + escape (value)+";path="+"/";
            }
            //设置cookie :value为日期时
            function setDateCookie(name, value) {
                var Days = 30;
                var exp = new Date();
                exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
                document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
            }
            //获取cookie
            function getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                console.log(arr);
                if (arr = document.cookie.match(reg))
                    return unescape(arr[2]);
                else
                    return null;
            }
            //删除cookie
            function delCookie(name) {
                var exp = new Date();
                exp.setTime(exp.getTime() - 1);
                var cval = getCookie(name);
                if (cval != null)
                    document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
            }
            var commonUtil = {
                /**
                 * 弹出消息框
                 * param msg 消息内容
                 * param type 消息框类型（参考bootstrap的alert）
                 */
                alert: function (title, msg, type) {
                    if (typeof (type) == "undefined") { // 未传入type则默认为success类型的消息框
                        type = "success";
                    }
                    // 创建bootstrap的alert元素
                    var divElement = $("<div></div>").addClass('alert').addClass('alert-' + type).addClass('alert-dismissible').addClass('col-md-4').addClass('col-md-offset-4');
                    divElement.css({ // 消息框的定位样式
                        "position": "absolute",
                        "right": "20px",
                        "top": "80px"
                    });

                    divElement.text(title); // 设置消息框的内容
                    var h = $('<h5><i class="icon-ok-sign"></i>' + msg + '</h5>');
                    $(divElement).append(h);
                    // 消息框添加可以关闭按钮
                    var closeBtn = $('<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>');
                    $(divElement).append(closeBtn);
                    // 消息框放入到页面中
                    $('body').append(divElement);
                    return divElement;
                },

                /**
                 * 短暂显示后上浮消失的消息框
                 * param msg 消息内容
                 * param type 消息框类型
                 */
                message: function (title, msg, type) {
                    var divElement = commonUtil.alert(title, msg, type); // 生成Alert消息框
                    var isIn = false; // 鼠标是否在消息框中

                    divElement.on({ // 在setTimeout执行之前先判定鼠标是否在消息框中
                        mouseover: function () { isIn = true; },
                        mouseout: function () { isIn = false; }
                    });

                    // 短暂延时后上浮消失
                    setTimeout(function () {
                        var IntervalMS = 20; // 每次上浮的间隔毫秒
                        var floatSpace = 60; // 上浮的空间(px)
                        var nowTop = divElement.offset().top; // 获取元素当前的top值
                        var stopTop = nowTop - floatSpace;    // 上浮停止时的top值
                        divElement.fadeOut(IntervalMS * floatSpace); // 设置元素淡出

                        var upFloat = setInterval(function () { // 开始上浮
                            if (nowTop >= stopTop) { // 判断当前消息框top是否还在可上升的范围内
                                divElement.css({ "top": nowTop-- }); // 消息框的top上升1px
                            } else {
                                clearInterval(upFloat); // 关闭上浮
                                divElement.remove();    // 移除元素
                            }
                        }, IntervalMS);

                        if (isIn) { // 如果鼠标在setTimeout之前已经放在的消息框中，则停止上浮
                            clearInterval(upFloat);
                            divElement.stop();
                        }

                        divElement.hover(function () { // 鼠标悬浮时停止上浮和淡出效果，过后恢复
                            clearInterval(upFloat);
                            divElement.stop();
                        }, function () {
                            divElement.fadeOut(IntervalMS * (nowTop - stopTop)); // 这里设置元素淡出的时间应该为：间隔毫秒*剩余可以上浮空间
                            upFloat = setInterval(function () { // 继续上浮
                                if (nowTop >= stopTop) {
                                    divElement.css({ "top": nowTop-- });
                                } else {
                                    clearInterval(upFloat); // 关闭上浮
                                    divElement.remove();    // 移除元素
                                }
                            }, IntervalMS);
                        });
                    }, 1500);
                }
    };
</script>


@if (IsSectionDefined("JavascriptLink"))
{
    @RenderSection("JavascriptLink");
}
@if (IsSectionDefined("Javascript"))
{
    @RenderSection("Javascript");
}
@section Javascript{


}
